package com.z8888q.zstopwatch.rewrite;

import java.util.TimerTask;

import com.z8888q.zstopwatch.Zcountdown;

public class RewriteTimerTaskC extends TimerTask{
	
	private Zcountdown zcd;
	
	public RewriteTimerTaskC(Zcountdown zcd){
		this.zcd=zcd;
	}
	boolean dom(){
		if(dos()){
		if(zcd.time_m==-1){
			return true;
		}else {
			zcd.time_m--;
			return false;
		}
		}else return false;
	}
	
	boolean dos(){
		if(doms()){
		if(zcd.time_s==0){
			if(zcd.time_m>0)zcd.time_s=59;
			zcd.handler2c.sendEmptyMessage(0);
			return true;
		}else 	{		
			zcd.time_s--;
			zcd.handler2c.sendEmptyMessage(0);
			return false;
		}
		}else return false;
	}
	
	boolean doms(){
			
		if(zcd.time_ms==0){
			if(zcd.time_s>0||zcd.time_m>0)zcd.time_ms=99;
			return true;
		}else {
			zcd.time_ms--;
			return false;
			}
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		
		
		
		
/*		zcd.time_ms--;
		if(zcd.time_ms<0)zcd.time_ms=999;
//		zcd.time_ms%=100;
		if(zcd.time_ms==0){
			zcd.time_s--;
			if(zcd.time_s<0)zcd.time_ms=59;
//			zcd.time_s%=60;
			if(zcd.time_s==0){
				zcd.time_m--;
				if(zcd.time_ms<0)zcd.time_ms=999;
//				zcd.time_m%=60;
				if(zcd.time_m==0){
					zcd.time_h++;
					zcd.time_h%=24;
				};
			};
		}*/
		if(!dom()){
			if(zcd.time_m<0){
				zcd.time_m=0;
				zcd.handler3c.sendEmptyMessage(0);
				if(zcd.timer!=null)	zcd.timer.cancel();
				zcd.timer=null;
			}
			zcd.handler.sendEmptyMessage(0);
		}
	}

}
